package com.embhealth.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.embhealth.dao.OrderSettingDao;
import com.embhealth.pojo.OrderSetting;
import com.embhealth.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 预约设置服务
 */
//发布服务
@Service(interfaceClass = OrderSettingService.class)
public class OrderSettingServiceImpl implements OrderSettingService {
    
    //注入dao
    @Autowired
    OrderSettingDao orderSettingDao;

    /**
     * 预约设置数据批量导入
     * @param orderSettings
     */
    @Override
    public void add(List<OrderSetting> orderSettings) {
        if (orderSettings!=null &&orderSettings.size()>0) {
            for (OrderSetting orderSetting : orderSettings) {
                this.editOrderSettingByIsSetOrderDate(orderSetting);
            }
        }
    }

    /**
     * 通过判断当前日期是否进行预约设置来操作预约数据
     * @param orderSetting
     */
    private void editOrderSettingByIsSetOrderDate(OrderSetting orderSetting) {
        //判断当前日期是否已经进行了预约设置
        long count= orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
        if (count>0) {
            //表示已经进行了预约设置,则执行更新操作
            orderSettingDao.updateNumByOrderDate(orderSetting);
        } else {
            //表示未进行预约设置,则执行插入操作
            orderSettingDao.insert(orderSetting);
        }
    }

    /**
     * 根据月份查询对应的预约设置数据
     * @param date
     * @return
     */
    @Override
    public List<Map> getOrderSettingByMonth(String date) {
        return orderSettingDao.getOrderSettingByMonth(date);
    }

    /**
     * 根据当前日期编辑可预约人数
     * @param orderSetting
     */
    @Override
    public void editNumberByOrderDate(OrderSetting orderSetting) {
        this.editOrderSettingByIsSetOrderDate(orderSetting);
    }
}
